package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.entity.vo.OrderVO;
import edu.ynu.se.xiecheng.achitectureclass.entity.vo.Result;
import edu.ynu.se.xiecheng.achitectureclass.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author laruui
 * @since 2023-12-07
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;


    @GetMapping("/pageOrder/{current}/{size}/{userId}")
    public Result pageOrder(@PathVariable("current") int current, @PathVariable("size") int size, @PathVariable("userId") String userId) {
        return orderService.pageOrder(current, size, userId);
    }

    @PostMapping("/addOrder/{totalPrice}")
    public Result addOrder(@RequestBody List<OrderVO> orderVOList, @PathVariable("totalPrice") float totalPrice) {
        log.info(String.valueOf(totalPrice));
        log.info(orderVOList.toString());
        return orderService.addOrder(orderVOList, totalPrice);
    }

    @GetMapping("/removeOrder/{sn}")
    public Result removeOrder(@PathVariable("sn") String sn) {
        return orderService.removeOrder(sn);
    }

    @GetMapping("/paymentOrder/{sn}")
    public Result paymentOrder(@PathVariable("sn") String sn) {
        return orderService.paymentOrder(sn);
    }

    @GetMapping("/enterOrder/{sn}")
    public Result enterOrder(@PathVariable("sn") String sn) {
        return orderService.enterOrder(sn);
    }

    @GetMapping("/returnAmountOrder/{sn}")
    public Result returnAmountOrder(@PathVariable("sn") String sn) {
        return orderService.returnAmountOrder(sn);
    }
}

